home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
telecomm
/
sticpsrc.lzh
/
SOURCE.ARC
/
SESSION.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-12
|
10KB
|
461 lines
/* Session control */
#include <stdio.h>
#include "config.h"
#include "global.h"
#include "mbuf.h"
#include "netuser.h"
#include "timer.h"
#include "tcp.h"
#include "ax25.h"
#include "lapb.h"
#include "ftp.h"
#include "telnet.h"
#include "finger.h"
#ifdef SCREEN
#include "screen.h"
#endif
#include "session.h"
#include "cmdparse.h"
struct session *sessions;
struct session *current;
char notval[] = "Not a valid control block\n";
static char badsess[] = "Invalid session\n";
static char nocurr[] = "No current session\n";
static char noupload[] = "Uploading on %s channel not supported\n";
/* Convert a character string containing a decimal session index number
* into a pointer. If the arg is NULLCHAR, use the current default session.
* If the index is out of range or unused, return NULLSESSION.
*/
static struct session *
sessptr(cp)
char *cp;
{
register struct session *s;
unsigned int i;
if(cp == NULLCHAR){
s = current;
} else {
if((i = atoi(cp)) >= nsessions)
return NULLSESSION;
s = &sessions[i];
}
if(s == NULLSESSION || s->type == FREE)
return NULLSESSION;
return s;
}
/* Select and display sessions */
dosession(argc,argv)
int argc;
char *argv[];
{
struct session *s;
extern char *tcpstates[];
extern char *ax25states[];
char *tcp_port();
if(argc > 1){
#ifdef SCREEN
current->win->active = 0;
#endif
if((current = sessptr(argv[1])) != NULLSESSION){
#ifdef SCREEN
current->win->active = 1;
#endif
go();
}
return 0;
}
printf(" # &CB Type Rcv-Q Snd-Q State Remote socket\n");
for(s=sessions; s < &sessions[nsessions];s++){
switch(s->type){
#ifdef IP
case TELNET:
printf("%c%-3ld%8lx Telnet %4d %4d %-13s%-s:%s",
(current == s)? '*':' ',
(long)(s - sessions),
ptr2long(s->cb.telnet->tcb),
s->cb.telnet->tcb->rcvcnt,
s->cb.telnet->tcb->sndcnt,
tcpstates[s->cb.telnet->tcb->state],
s->name,
tcp_port(s->cb.telnet->tcb->conn.remote.port));
break;
#ifdef FTPC
case FTP:
printf("%c%-3ld%8lx FTP %4d %4d %-13s%-s:%s",
(current == s)? '*':' ',
(long)(s - sessions),
ptr2long(s->cb.ftp->control),
s->cb.ftp->control->rcvcnt,
s->cb.ftp->control->sndcnt,
tcpstates[s->cb.ftp->control->state],
s->name,
tcp_port(s->cb.ftp->control->conn.remote.port));
break;
#endif
#endif
#ifdef AX25
case AX25TNC:
printf("%c%-3ld%8lx AX25 %4d %4d %-13s%-s",
(current == s)? '*':' ',
(long)(s - sessions),
ptr2long(s->cb.ax25_cb),
len_mbuf(s->cb.ax25_cb->rxq),
len_q(s->cb.ax25_cb->txq),
ax25states[s->cb.ax25_cb->state],
s->name);
break;
#endif
#ifdef IP
case FINGER:
printf("%c%-3ld%8lx Finger %4d %4d %-13s%-s:%s",
(current == s)? '*':' ',
(long)(s - sessions),
ptr2long(s->cb.finger->tcb),
s->cb.finger->tcb->rcvcnt,
s->cb.finger->tcb->sndcnt,
tcpstates[s->cb.finger->tcb->state],
s->name,
tcp_port(s->cb.finger->tcb->conn.remote.port));
break;
#endif
default:
continue;
}
if(s->rfile != NULLCHAR || s->ufile != NULLCHAR)
printf("\t");
if(s->rfile != NULLCHAR)
printf("Record: %s ",s->rfile);
if(s->ufile != NULLCHAR)
printf("Upload: %s",s->ufile);
printf("\n");
}
return 0;
}
/* Enter conversational mode with current session */
int
go()
{
void rcv_char(),ftpccr(),ax_rx();
if(current == NULLSESSION || current->type == FREE)
return 0;
mode = CONV_MODE;
#ifdef SCREEN
Activate(current->win);
#endif
switch(current->type){
#ifdef IP
case TELNET:
if(current->cb.telnet->remote[TN_ECHO])
raw(); /* Re-establish raw mode if it was set */
rcv_char(current->cb.telnet->tcb,0); /* Get any pending input */
break;
#ifdef FTPC
case FTP:
ftpccr(current->cb.ftp->control,0);
break;
#endif
#endif
#ifdef AX25
case AX25TNC:
ax_rx(current->cb.ax25_cb,0);
break;
#endif
#ifdef IP
case FINGER:
fingcli_rcv(current->cb.finger->tcb,0);
break;
#endif
}
return 0;
}
doclose(argc,argv)
int argc;
char *argv[];
{
struct session *s;
if((s = sessptr(argc > 1 ? argv[1] : NULLCHAR)) == NULLSESSION){
printf(badsess);
return -1;
}
switch(s->type){
#ifdef IP
case TELNET:
close_tcp(s->cb.telnet->tcb);
break;
#ifdef FTPC
case FTP:
close_tcp(s->cb.ftp->control);
break;
#endif
#endif
#ifdef AX25
case AX25TNC:
if (argv[0][0] == 'c')
close_ax25(s->cb.ax25_cb);
else
disc_ax25(s->cb.ax25_cb);
break;
#endif
#ifdef IP
case FINGER:
close_tcp(s->cb.finger->tcb);
break;
#endif
}
return 0;
}
doreset(argc,argv)
int argc;
char *argv[];
{
struct session *s;
if((s = sessptr(argc > 1 ? argv[1] : NULLCHAR)) == NULLSESSION){
printf(badsess);
return -1;
}
switch(s->type){
#ifdef IP
case TELNET:
reset_tcp(s->cb.telnet->tcb);
break;
#ifdef FTPC
case FTP:
if(s->cb.ftp->data != NULLTCB){
reset_tcp(s->cb.ftp->data);
s->cb.ftp->data = NULLTCB;
}
reset_tcp(s->cb.ftp->control);
break;
#endif
#endif
#ifdef AX25
case AX25TNC:
reset_ax25(s->cb.ax25_cb);
break;
#endif
#ifdef IP
case FINGER:
reset_tcp(s->cb.finger->tcb);
break;
#endif
}
return 0;
}
int
dokick(argc,argv)
int argc;
char *argv[];
{
void tcp_timeout();
struct session *s;
if((s = sessptr(argc > 1 ? argv[1] : NULLCHAR)) == NULLSESSION){
printf(badsess);
return -1;
}
switch(s->type){
#ifdef IP
case TELNET:
if(kick_tcp(s->cb.telnet->tcb) == -1){
printf(notval);
return 1;
}
break;
#ifdef FTPC
case FTP:
if(kick_tcp(s->cb.ftp->control) == -1){
printf(notval);
return 1;
}
if(s->cb.ftp->data != NULLTCB)
kick_tcp(s->cb.ftp->data);
break;
#endif
#endif
#ifdef AX25
case AX25TNC:
if(kick_ax25(s->cb.ax25_cb) == -1){
printf(notval);
return 1;
}
break;
#ifdef IP
case FINGER:
if(kick_tcp(s->cb.finger->tcb) == -1){
printf(notval);
return 1;
}
break;
#endif
default:
return 1;
#endif
}
return 0;
}
struct session *
newsession()
{
register int i;
for(i=0;i<nsessions;i++)
if(sessions[i].type == FREE){
#ifdef SCREEN
struct win *makewindow();
if ((sessions[i].win = makewindow()) == NULL)
return NULLSESSION;
sessions[i].win->active = 1;
#endif
return &sessions[i];
}
return NULLSESSION;
}
freesession(s)
struct session *s;
{
if(s == NULLSESSION || s < sessions || s >= &sessions[nsessions])
return;
if(s->record != NULLFILE){
fclose(s->record);
s->record = NULLFILE;
}
if(s->rfile != NULLCHAR){
free(s->rfile);
s->rfile = NULLCHAR;
}
if(s->upload != NULLFILE){
fclose(s->upload);
s->upload = NULLFILE;
}
if(s->ufile != NULLCHAR){
free(s->ufile);
s->ufile = NULLCHAR;
}
if(s->name != NULLCHAR){
free(s->name);
s->name = NULLCHAR;
}
#ifdef SCREEN
freewindow(s->win);
#endif
s->type = FREE;
}
/* Control session recording */
dorecord(argc,argv)
int argc;
char *argv[];
{
if(current == NULLSESSION || current->type == FREE){
printf(nocurr);
return 1;
}
if(argc > 1){
if(current->rfile != NULLCHAR){
fclose(current->record);
free(current->rfile);
current->record = NULLFILE;
current->rfile = NULLCHAR;
}
/* Open new record file, unless file name is "off" or "stop",
* which means disable recording
*/
if(strcmp(argv[1],"off") != 0 && strcmp(argv[1],"stop") != 0
&& (current->record = fopen(argv[1],binmode[APPEND_BINARY])) != NULLFILE){
current->rfile = malloc((unsigned)strlen(argv[1])+1);
strcpy(current->rfile,argv[1]);
}
}
if(current->rfile != NULLCHAR)
printf("Recording into %s\n",current->rfile);
else
printf("Recording off\n");
return 0;
}
/* Control file transmission */
doupload(argc,argv)
int argc;
char *argv[];
{
struct tcb *tcb;
struct ax25_cb *axp;
int16 window;
if(current == NULLSESSION || current->type == FREE){
printf(nocurr);
return 1;
}
if(argc > 1){
switch(current->type){
#ifdef IP
cas